package hopital.orm;

import hopital.sql.SqlObject;
import hopital.sql.SqlQuery;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Analyze extends SqlObject{
    
    private int _laboratoire,_patient ;
    private String _date,_type ,_resultat ,_remarque,_etat;

    public String getType() {
        return _type;
    }

    public void setType(String _type) {
        this._type = _type;
    }

    public String getResultat() {
        return _resultat;
    }

    public void setResultat(String _resultat) {
        this._resultat = _resultat;
    }

    public String getRemarque() {
        return _remarque;
    }

    public void setRemarque(String _remarque) {
        this._remarque = _remarque;
    }

    public String getEtat() {
        return _etat;
    }

    public void setEtat(String _etat) {
        this._etat = _etat;
    }
    
    public int getLaboratoire() {
        return _laboratoire;
    }

    public void setLaboratoire(int _laboratoire) {
        this._laboratoire = _laboratoire;
    }

    public int getPatient() {
        return _patient;
    }

    public void setPatient(int _patient) {
        this._patient = _patient;
    }

    public String getDate() {
        return _date;
    }

    public void setDate(String _date) {
        this._date = _date;
    }

    public Analyze(int _laboratoire, int _patient, String _date, String _type, String _resultat, String _remarque) {
        this._laboratoire = _laboratoire;
        this._patient = _patient;
        this._date = _date;
        this._type = _type;
        this._resultat = _resultat;
        this._remarque = _remarque;
    }

   


    

    public Analyze() {
    }

    
    
    private Analyze(ResultSet _rs) throws SQLException {
       this(_rs.getInt("c_labo"), _rs.getInt("c_patient"), _rs.getString("c_date"),_rs.getString("c_type"),_rs.getString("c_resultat"),_rs.getString("c_remarque"));
       this._id=_rs.getInt("c_id");
    }
    
    @Override
    public SqlQuery insert() {
        return new SqlQuery("INSERT INTO t_analyzes (c_labo,c_patient,c_date,c_type ,c_resultat ,c_remarque) VALUES(?,?,?,?,?,?);",_laboratoire,_patient,_date,_type ,_resultat ,_remarque);
    }

    @Override
    public SqlQuery update() {
        return new SqlQuery("UPDATE t_analyzes SET c_etat=? WHERE c_id=?;",_id,_etat);
    }

    @Override
    public SqlQuery delete() {
        return new SqlQuery("DELETE FROM t_analyzes WHERE c_id=?;", _id);
    }

    @Override
    public SqlQuery select() {
        if(_id!=-1){
            return new SqlQuery("SELECT * FROM t_analyzes WHERE c_id=?;", _id);
        }else if(_patient!=0){
            return new SqlQuery("SELECT * FROM t_analyzes WHERE c_patient=?;", _patient);
        }else{
            return new SqlQuery("SELECT * FROM t_analyzes;");
        }
    }

    @Override
    public List<Object> getTable(ResultSet _rs) throws Exception {
        List<Object> list=new ArrayList<>();
        while (_rs.next()) {            
            list.add(new Analyze(_rs));
        }
        return list;
    }
}
